﻿using BCDto.TMS.MarketingCoupon.MarketingCouponType;
using BCDto.TMS.MarketingCoupon.MarketingCouponType.MarketingCouponTypeRequest;
using BCService.TMS.MarketingCoupon.MarketingCouponType;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace BCTMSRESTful.Controllers.Management.TMS.MarketingCoupon
{
    /// <summary>
    /// 优惠券类型
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class MarketingCouponTypeController : ManagementBaseController
    {
        private readonly IMarketingCouponTypeService marketingCouponTypeService;
        public MarketingCouponTypeController(IMarketingCouponTypeService marketingCouponTypeService)
        {
            this.marketingCouponTypeService = marketingCouponTypeService;
        }

        /// <summary>
        /// 创建优惠券类型。
        /// </summary>
        /// <param name="requestDto">优惠券类型信息</param>
        /// <response code="201">创建优惠券类型。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建优惠券类型")]
        [ProducesResponseType(typeof(MarketingCouponTypeDto), 200)]
        public IActionResult AgentCreate([FromBody] MarketingCouponTypeRequestDto requestDto)
        {
            var result = this.marketingCouponTypeService.AgentCreate(requestDto, this.Admin);
            return this.Ok(result);
        }

        /// <summary>
        /// 设置优惠券可选地区
        /// </summary>
        /// <param name="marketingCouponTypeId">优惠券类型id</param>
        /// <param name="requestDto">地区列表</param>
        /// <response code="201">设置优惠券可选地区。</response>
        /// <returns></returns>
        [HttpPut("[action]/{marketing_coupon_type_id}")]
        [Log("设置优惠券可选地区")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult SetAddress([FromRoute(Name = "marketing_coupon_type_id")] long marketingCouponTypeId,
            [FromBody] MarketingCouponAddressRequestDto requestDto)
        {
            var result = this.marketingCouponTypeService.SetAddress(marketingCouponTypeId, requestDto, this.Admin);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取优惠券类型信息
        /// </summary>
        /// <param name="marketingCouponTypeId">优惠券类型id</param>
        /// <returns></returns>
        [HttpGet("{marketing_coupon_type_id}")]
        [ProducesResponseType(typeof(MarketingCouponTypeViewDto), 200)]
        public IActionResult GetSingle([FromRoute(Name = "marketing_coupon_type_id")] long marketingCouponTypeId)
        {
            var result = this.marketingCouponTypeService.GetSingle(marketingCouponTypeId);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取优惠券类型列表
        /// </summary>
        /// <param name="isEnabled">是否可用</param>
        /// <param name="couponMinAmount">优惠最小金额</param>
        /// <param name="couponMaxAmount">优惠最大金额</param>
        /// <param name="isValid">是否有效</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<MarketingCouponTypeViewDto>), 200)]
        public IActionResult GetList([FromQuery(Name = "is_enabled")] bool? isEnabled,
            [FromQuery(Name = "coupon_min_amount")] decimal? couponMinAmount,
            [FromQuery(Name = "coupon_max_amount")] decimal? couponMaxAmount,
            [FromQuery(Name = "is_valid")] bool? isValid)
        {
            var result = this.marketingCouponTypeService.GetList(this.Admin, isEnabled, isValid, couponMinAmount, couponMaxAmount);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改优惠券类型是否可用
        /// </summary>
        /// <param name="marketingCouponTypeId">优惠券类型id</param>
        /// <param name="enabled">是否可用</param>
        /// <returns></returns>
        [HttpPut("[action]/{marketing_coupon_type_id}/{enabled}")]
        [Log("修改优惠券类型是否可用")]
        [ProducesResponseType(typeof(NoContentResult), 200)]
        public IActionResult Enabled([FromRoute(Name = "marketing_coupon_type_id")] long marketingCouponTypeId,
            [FromRoute(Name = "enabled")] bool enabled)
        {
            if (enabled)
                marketingCouponTypeService.Enabled(marketingCouponTypeId, this.Admin);
            else
                marketingCouponTypeService.Disabled(marketingCouponTypeId, this.Admin);
            return NoContent();
        }

    }
}
